package Controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import MemberAction.MemberDeleteAction;
import MemberAction.MemberFindAction;
import MemberAction.MemberIdCheckAction;
import MemberAction.MemberJoinAction;
import MemberAction.MemberLoginAction;
import MemberAction.MemberModifyAction_1;
import MemberAction.MemberModifyAction_2;
import MemberAction.MemberZipcodeAction;
import MemberAction.MemberZipcodeAction2;

@WebServlet("*.mem")
public class MemberController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public MemberController() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String reqUri = request.getRequestURI();
		String contPath = request.getContextPath();
		String cmd = reqUri.substring(contPath.length());
		
		if(cmd.equals("/idcheck.mem")){
			MemberIdCheckAction idcheck = new MemberIdCheckAction();
			idcheck.execute(request, response);
		}else if(cmd.equals("/zipcode.mem")){
			MemberZipcodeAction zipcode = new MemberZipcodeAction();
			zipcode.execute(request, response);
		}else if(cmd.equals("/zipsearch.mem")){
			MemberZipcodeAction2 zipcode2 = new MemberZipcodeAction2();
			zipcode2.execute(request, response);
		}else if(cmd.equals("/memjoin.mem")){
			MemberJoinAction join = new MemberJoinAction();
			join.execute(request, response);
		}else if(cmd.equals("/login.mem")){
			MemberLoginAction login = new MemberLoginAction();
			login.execute(request, response);
		}else if(cmd.equals("/joinForm.mem")){
			openPage("./member/member_join.jsp", response); 
		}else if(cmd.equals("/idfind.mem")){
			MemberFindAction find = new MemberFindAction();
			find.execute(request, response);
		}else if(cmd.equals("/findForm.mem")){
			openPage("./member/member_find.jsp", response); 
		}else if(cmd.equals("/modifyform.mem")){
			MemberModifyAction_1 modiform = new MemberModifyAction_1();
			modiform.execute(request, response);
		}else if(cmd.equals("/modify.mem")){
			MemberModifyAction_2 modi = new MemberModifyAction_2();
			modi.execute(request, response);
		}else if(cmd.equals("/memout.mem")){
			openPage("./member/member_out.jsp", response); 
		}else if(cmd.equals("/memdel.mem")){
			MemberDeleteAction memdelete = new MemberDeleteAction();
			memdelete.execute(request, response);
		}else if(cmd.equals("/memlogin.mem")){
			openPage("./member/member_login.jsp", response); 
		}
	}
	
	public void openPage(String page, HttpServletResponse response){
		try {
			response.sendRedirect(page);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
